package com.hcss.common.util;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

public class XmlUtil {
	public static final Document parseStringToXml(String sMsg) throws Exception{
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		StringReader sr = new StringReader(sMsg);
		InputSource is = new InputSource(sr);
		Document document = db.parse(is);
		return document;
	}
	
	public static final NodeList getElement(Document document, String name) {
		Element root = document.getDocumentElement();
		NodeList nodelist = root.getElementsByTagName(name);
		return nodelist;
	}
}
